package project07;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;

/**
 * <p>Title: Project 7</p>
 * <p>Description: CS 235 Project #7
 *       Shows how to get started with using abstract classes.</p>
 * @author Anthony Varghese
 * @date   February 5th 2012
 * @version 1.0
 */
public class MainClient extends JFrame implements ActionListener {
	/**
	 * Data members
	 * serialVersionUID is for serialization - ignore this for now.
	 * 
	 */
	private static final long serialVersionUID = 1L;
	// Position and size of the window frame
	private static final int FRAME_TOP_LEFT_X = 200; // pixels from left edge of screen
	private static final int FRAME_TOP_LEFT_Y = 200; // pixels from top edge of screen
	private static final int FRAME_WIDTH  = 400;     // pixels wide
	private static final int FRAME_HEIGHT = 300;	 // pixels high

	private JLabel text; // Tells user what to do
	private String DESCRIPTION = "Let's draw stuff.";
	// Position and size of the description label
	private static final int LABEL_TOP_LEFT_X = 30; // pixels from left edge of window
	private static final int LABEL_TOP_LEFT_Y = 0; // pixels from top edge of window
	private static final int LABEL_WIDTH = FRAME_WIDTH - 2*30; // pixels wide
	private static final int LABEL_HEIGHT = 30;   // pixels high

	private JComboBox shapeChooser; // allows user to select a shape
	private String[] shapeNames = { "Line", "Triangle", "Square", "Rectangle" };
	// Position and size of ComboBox
	private static final int COMBOBOX_TOP_LEFT_X = LABEL_TOP_LEFT_X;  // as before, all pixels
	private static final int COMBOBOX_TOP_LEFT_Y = LABEL_TOP_LEFT_Y + LABEL_HEIGHT + 10;
	private static final int COMBOBOX_WIDTH = (int)(FRAME_WIDTH * 0.4);
	private static final int COMBOBOX_HEIGHT = 30;

	private JButton drawButton; // Allows us to draw shapes in a list
	// Position and size of the delete button
	private static final int BUTTON_TOP_LEFT_X = LABEL_TOP_LEFT_X + 150; // pixels from left edge of window
	private static final int BUTTON_TOP_LEFT_Y = LABEL_TOP_LEFT_Y; // pixels from top edge of window
	private static final int BUTTON_WIDTH = 90; // pixels wide
	private static final int BUTTON_HEIGHT = 40;   // pixels high

	
	/**
	 * Shape array - an array of shapes
	 */
	private final int NUMBER_OF_SHAPES = 100;
	Shape[] shapeArray = new Shape[NUMBER_OF_SHAPES];

	
	/**
	 * MainClient default constructor
	 * 
	 */
	public MainClient() {
		setUpWindow();
	}

	/**
	 * MainClient constructor
	 * @param arg0 - title string
	 */
	public MainClient(String arg0) {
		super(arg0);
		setUpWindow();

	}

	/**
	 * setUpWindow - add all the doo-dads we need in the window.
	 * 
	 */
	private void setUpWindow() {
		setBounds( FRAME_TOP_LEFT_X, FRAME_TOP_LEFT_Y, FRAME_WIDTH, FRAME_HEIGHT);
		// Without the next line, the program is still running even if the window is "closed"
		setDefaultCloseOperation(EXIT_ON_CLOSE);
		// We want to position our components - labels and buttons - ourselves. So disable
		//   any default layout managers that might try to position things
		setLayout( null );
		
		text = new JLabel( DESCRIPTION );
		text.setBounds(LABEL_TOP_LEFT_X, LABEL_TOP_LEFT_Y, LABEL_WIDTH, LABEL_HEIGHT);
		add( text );
		
		// set up Combo box
		shapeChooser = new JComboBox( shapeNames ); // set up Combo box with the array of shapes
		shapeChooser.addItem( "Select a shape" );
		shapeChooser.setSelectedIndex( shapeNames.length );
		shapeChooser.setBounds(COMBOBOX_TOP_LEFT_X, COMBOBOX_TOP_LEFT_Y, COMBOBOX_WIDTH, COMBOBOX_HEIGHT);
		add( shapeChooser );
		shapeChooser.addActionListener( this );
		
		drawButton = new JButton("Draw");
		drawButton.setBounds(BUTTON_TOP_LEFT_X, BUTTON_TOP_LEFT_Y, BUTTON_WIDTH, BUTTON_HEIGHT);
		add( drawButton );
		drawButton.addActionListener(this);
	}

	/**
	 * actionPerformed method for MainClient
	 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
	 */
	@Override
	public void actionPerformed(ActionEvent arg0) {
		shapeArray[0] = new Shape();
		shapeArray[1] = new Shape();
		
		repaint();
	}

	/**
	 * Paint method - this is where our shapes get drawn.
	 */
	public void paint(java.awt.Graphics graphics) {
		super.paint(graphics);
		/**
		 * We want to get the following loop to draw all the things in
		 * the shape array.
		 */
		for( Shape s : shapeArray)
			if (s != null)
				s.draw(graphics);
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		(new MainClient("Project 7")).setVisible(true);
		
	}

}
